#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.${artifactId}.utils;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.TopLevelClass;

import java.util.List;

public class RenameFilePlugin extends PluginAdapter {


    @Override
    public void initialized(IntrospectedTable introspectedTable) {
        // 更改实体类名称，例如：cn.zzs.mybatis.entity.Menu => cn.zzs.mybatis.entity.MenuDomain
        String oldType = introspectedTable.getBaseRecordType();
        introspectedTable.setBaseRecordType(oldType + "DO");
        // 更改Mapper名称
        String mapperType = introspectedTable.getMyBatis3JavaMapperType();
        introspectedTable.setMyBatis3JavaMapperType(mapperType.replace("Mapper", "DAO"));
    }

    @Override
    public boolean modelBaseRecordClassGenerated(
            TopLevelClass topLevelClass,
            IntrospectedTable introspectedTable) {

        // 在生成的Mapper接口上添加@Mapper注解
        topLevelClass.addImportedType("org.apache.ibatis.annotations.Mapper");
        topLevelClass.addAnnotation("@Mapper");

        // 继承自Object类
        topLevelClass.setSuperClass(new FullyQualifiedJavaType("java.lang.Object"));

        return true;
    }

    @Override
    public boolean clientGenerated(Interface interfaze,
                                   TopLevelClass topLevelClass,
                                   IntrospectedTable introspectedTable) {

        // 在生成的Mapper接口上添加@Mapper注解
        topLevelClass.addImportedType("org.apache.ibatis.annotations.Mapper");
        topLevelClass.addAnnotation("@Mapper");

        // 继承自Object类
        topLevelClass.setSuperClass(new FullyQualifiedJavaType("java.lang.Object"));
        return true;
    }

    @Override
    public boolean modelExampleClassGenerated(
            TopLevelClass topLevelClass,
            IntrospectedTable introspectedTable) {

        topLevelClass.addImportedType("javax.persistence.Entity");
        topLevelClass.addAnnotation("@Entity");

        return true;
    }

    @Override
    public boolean validate(List<String> list) {
        return false;
    }
}

